<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
  <head>
    <title>天安财险</title>
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
    <script src="${ctxStatic }/layer/layer.js" type="text/javascript"></script>
    <script src="${ctxStatic }/js/utils.js" type="text/javascript"></script>
    
    <script type="text/javascript">
	    $(function() {
			$("#orgname").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
    </script>
    
  </head>
  
  <body>
  	<ul class="nav nav-tabs">
		<li><a href="${ctx}/org/list">机构列表</a></li>
		<li class="active"><a href="javascript:void(0);">机构添加</a></li>
	</ul>

	<form:form id="inputForm" commandName="inputForm" class="form-horizontal" action="${ctx}/org/save" method="post" modelAttribute="item">
		<form:hidden path="id" />  
		<form:hidden path="orgpid" />  
		
		<div class="control-group">
			<label class="control-label">上级机构:</label>
			<div class="controls">
				<div class="input-append">
					<form:hidden path="parent.id" /> 
					<form:input path="parent.orgname" readonly="true" />
				</div>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">机构名称:</label>
			<div class="controls">
				<form:input path="orgname" cssClass="required" type="text" maxlength="30"/>
				<span class="help-inline"><span style="color:red">*</span> </span>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">机构简称:</label>
			<div class="controls">
				<form:input id="orgshortname" path="orgshortname" cssClass="required" type="text"  maxlength="30"/>
				<span class="help-inline"><span style="color:red">*</span> </span>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">机构编码:</label>
			<div class="controls">
				<form:input id="code" path="orgcode" cssClass="required" type="text" maxlength="30"/>
				<span class="help-inline"><span style="color:red">*</span> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">机构类型:</label>
			<div class="controls">
				<form:select id="type" path="orgtype" class="input-medium">
					<form:option value="1">公司</form:option>
					<form:option value="2" selected="selected">部门</form:option>
					<form:option value="3">小组</form:option>
					<form:option value="4">其它</form:option>
				</form:select>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">地址:</label>
			<div class="controls">
				<form:input id="orgaddr" path="orgaddr" type="text" />
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">负责人:</label>
			<div class="controls">
				<form:input id="orgContacts" path="orgContacts" type="text"  />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">电话:</label>
			<div class="controls">
				<form:input id="phone" path="orgofficephone" type="text"  />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注:</label>
			<div class="controls">
				<form:textarea id="remarks" path="remarks"  class="input-xlarge" rows="3"/>
			</div>
		</div>
		<div class="form-actions">
			<input id="btnSubmit" class="btn btn-primary" type="submit"  value="保 存"/>&nbsp;
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
    
    
    <script type="text/javascript">
    //onclick="ms_save()"
    function ms_save(){
    	var params = $("#inputForm").serializeArray();
        var json = tm_parseParams(params);
        
    	$.ajax({
				dataType : "json",
				type : "POST",
				url : "${ctx}/org/save",
				data : params,
				success : function(data){
					if(data.result == "1"){
						layer.alert("保存成功");
					}
				},
				error : function(e){
					for(var k in e){
						console.log(k + "====="+e[k]);
					}
					layer.alert("保存失败");
				}
			});
	}
    
    </script>
  </body>
</html>
